package com.ndp.fb.rdb.model.message;

import com.ndp.fb.enums.message.ChannelType;
import com.ndp.fb.enums.message.EventNotificationType;
import com.ndp.fb.enums.message.MessageStatus;
import com.ndp.fb.rdb.annotation.Column;
import com.ndp.fb.rdb.annotation.ColumnType;
import com.ndp.fb.rdb.annotation.Id;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

/**
 * Created by elvisxiong on 7/23/15.
 */
@Getter
@NoArgsConstructor
@Setter
public class EventNotificationMessage implements Serializable{
    //id
    @Id
    private Long id;
    //事件编号
    // event_no
    private String eventNo;
    //消息体 body
    private String body;
    //消息标题
    @Column
    private String subject;
    //消息发送者(user ticket)
    // sender
    private String sender;
    //消息接收者(user ticket)
    // receiver
    private String receiver;
    //消息发送时间
    // send_time
    private Long sendTime;
    // 消息状态
    // status
    @Column(type = ColumnType.Int)
    private MessageStatus status;

    //事件通知类型
    @Column(value = "event_type",type = ColumnType.Int)
    private EventNotificationType eventType;

    //参考 NotificationMessageKey
    // event_key
    private String eventKey;

    //xxx List<String> 转化的JSON串
    // event_values
    private String eventValues;

    //是否需要功能跳转
    // is_need_function_jump
    private Boolean isNeedFunctionJump = false;
    //消息跳转url
    // url
    private String url;
    /**
     * 消息是否阅读
     * <ul>
     * <li>0:未读</li>
     * <li>1:已读</li>
     * </ul>
     */
    //is_read
    private Integer isRead =0;
    //消息有效期
    @Column("expire_time")
    private Long expiredTime;
    //渠道
    // channel
    @Column(type = ColumnType.Int)
    private ChannelType channel;


    public void setEventType(int eventtype) {
        this.eventType=EventNotificationType.getEventNotificationType(eventtype);
    }

    public boolean isNeedFunctionJump() {
        return isNeedFunctionJump;
    }

    public ChannelType getChannel() {
        return channel;
    }

    public void setChannel(ChannelType channel) {
        this.channel = channel;
    }

    public void setChannel(int channel){
        switch (channel){
            case 0: this.channel = ChannelType.WEBSITE;break;
            case 1: this.channel = ChannelType.SMS;break;
            case 2: this.channel = ChannelType.EMAIL;break;
            case 3: this.channel = ChannelType.IPHONE;break;
            case 4: this.channel = ChannelType.ANDROID;break;
        }
    }

    public void setIsNeedFunctionJump(boolean needFunctionJump) {
        isNeedFunctionJump = needFunctionJump;
    }
    public void setNeedFunctionJump(boolean needFunctionJump) {
        isNeedFunctionJump = needFunctionJump;
    }



    public EventNotificationType getEventType() {
        return eventType;
    }

    public MessageStatus getStatus() {
        return status;
    }

    public void setStatus(int status){
        if( status == 1){
            this.status = MessageStatus.NORMAL;
        }else{
            this.status = MessageStatus.DELETEED;
        }

    }


}
